import vnode from "./vnode";
// 实现一个低配版
// 调用时是这种形式
// h('div',{},"文字")
// h('div',{},[])
// h('div',{},h())
export default function (sel, data, c) {
  if (arguments.length != 3) {
    throw Error("这是低配版h函数，必须是3个参数");
  }
  if (typeof c == "string" || typeof c == "number") {
    return vnode(sel, data, undefined, c, undefined);
  } else if (Array.isArray(c)) {
    let children = [];
    for (let i = 0; i < c.length; i++) {
      if (!(typeof c[i] == "object" && c[i].hasOwnProperty("sel"))) {
        throw Error("h函数的参数形式有错");
      } else {
        children.push(c[i]);
      }
    }
    return vnode(sel, data, children, undefined, undefined);
  } else if (typeof c == "object" && c.hasOwnProperty("sel")) {
    let children = [c];
    return vnode(sel, data, children, undefined, undefined);
  } else {
    throw Error("h函数的参数形式有错");
  }
}
